package com.xiaoqian.partyembassy.tools;

import android.os.Handler;

/**
 * 全局定时器
 * @author Administrator
 *
 */
public abstract class CountTimeMachines {
	private static  int DELAY = 2000;
	private boolean isRuning;
	Handler printHandler = new Handler();
	Runnable printStuff = new Runnable(){
	     @Override
	     public void run(){
	    	 if(isRuning){
		    	 onTick();
		    	 printHandler.postDelayed(this, DELAY);
	    	 }
	     }
	};
	public abstract void onTick();
	/**
	 * Callback fired when the time is up.
	 */
	public void starTime(){
		isRuning = true;
		if(printStuff != null){
			printHandler.removeCallbacks(printStuff);
		}
		printHandler.postDelayed(printStuff, 0);
	}
	public void stopTime(){
		if(printHandler != null){
			isRuning=false;
			printHandler.removeCallbacks(printStuff);
		}
	}
}
